package com.zjxny.jobs;

import java.util.Date;

import javax.annotation.Resource;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import lombok.extern.slf4j.Slf4j;
import xyz.erupt.core.annotation.EruptHandlerNaming;
import xyz.erupt.job.handler.EruptJobHandler;

/**
 * 第天执行一次
 */
@Slf4j
@Service
@EruptHandlerNaming("更新违章未处理任务")
public class UpdateTrafficTaskStatusJob implements EruptJobHandler {
	
	@Resource
	JdbcTemplate jdbcTemplate;
	
	@Override
	public String exec(String code, String param) {
	
		Date ctime = new Date();
		if(StrUtil.isNotBlank(param)) {	
			ctime = DateUtil.parse(param);
		}
		
		String dateOne = DateUtil.format(DateUtil.offsetDay(ctime,-3), DatePattern.NORM_DATE_PATTERN);
		String sqlOne =String.format("update sms_info set update_time=now(), status=0,sms_tpl_info_id=2 where status=1 and last_send_date='%s'",dateOne);
		int affectOne = jdbcTemplate.update(sqlOne);
		
		String dateTwo = DateUtil.format(DateUtil.offsetDay(ctime,15), DatePattern.NORM_DATE_PATTERN);
		String sqlTwo =String.format("update sms_info set update_time=now(), status=0,sms_tpl_info_id=3 where status=1 and last_send_date='%s'",dateTwo);
		int affectTwo = jdbcTemplate.update(sqlTwo);
		
		log.info("UpdateTrafficTaskStatusJob.exec affectNum={},affectNumExt={}",affectOne,affectTwo);
		
		return "更新成功";
	}
}
